package nettyTest.netty3Test.https;

import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.ssl.SslHandler;

import java.io.FileInputStream;
import java.security.KeyStore;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;

public class SSLContextFactory {
	public static SSLContext getSslContext() throws Exception {
		char[] passArray = "555555".toCharArray();
		SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
		KeyStore ks = KeyStore.getInstance("JKS");
		// 加载keytool 生成的文件
		FileInputStream inputStream = new FileInputStream("D:\\test.jks");
		ks.load(inputStream, passArray);
		KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
		kmf.init(ks, passArray);
		sslContext.init(kmf.getKeyManagers(), null, null);
		inputStream.close();
		return sslContext;

	}
}
